package com.campus_activity.campus_activity.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus_activity.campus_activity.common.PageResult;
import com.campus_activity.campus_activity.common.R;
import com.campus_activity.campus_activity.domain.dto.BasePageQueryDTO;
import com.campus_activity.campus_activity.domain.dto.SchoolDTO;
import com.campus_activity.campus_activity.domain.dto.SchoolQueryDTO;
import com.campus_activity.campus_activity.domain.dto.SchoolUpdateDTO;
import com.campus_activity.campus_activity.domain.po.School;
import com.campus_activity.campus_activity.domain.vo.ActivityVO;
import com.campus_activity.campus_activity.domain.vo.SchoolVo;
import com.campus_activity.campus_activity.mapper.SchoolMapper;
import com.campus_activity.campus_activity.service.SchoolService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author hb
 * @version 17
 */
@Tag(name = "学校接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/school")
public class SchoolController {

    private final SchoolService schoolService;


    @Operation(summary = "搜索学校或列所有学校")
    @PostMapping("/listSchool")
    public R<?> listSchoole(@RequestBody SchoolQueryDTO schoolQueryDTO){
        PageResult<SchoolVo> school = schoolService.listSchool(schoolQueryDTO);
        return R.success(school);
    }


    @Operation(summary = "添加学校")
    @PostMapping("/addSchool")
    public R<?> addSchool(@RequestBody SchoolDTO schoolDTO) {
        schoolService.addSchool(schoolDTO);
        return R.success("新增学校成功");
    }

    @Operation(summary = "修改学校信息")
    @PostMapping("/updateSchool")
    public R<?> updateSchool(@RequestBody SchoolUpdateDTO schoolDTO) {
        boolean b = schoolService.updateSchool(schoolDTO);
        if(b) {
            return R.success("修改学校信息成功");
        }else {
            return R.fail("修改学校信息失败");
        }
    }

    @Operation(summary = "删除学校")
    @PostMapping("/deleteSchool")
    public R<?> deleteSchool(String schoolId) {
        boolean b = schoolService.deleteSchool(schoolId);
        if(b) {
            return R.success("删除学校成功");
        }else {
            return R.fail("学校不存在或删除失败");
        }
    }

}
